# FIXME 重叠输出

class Solution:
    def convert(self, s: str, numRows: int) -> str:
        p, n = [], len(s)
        for i, j in enumerate(range(0,2*numRows,2)):
            e = (j,2*numRows-2-j)
            k = 0
            while i < n:
                z = e[k%2]
                i += z
                if z:
                    p.append(s[i])
                k += 1
        return ''.join(p)

if __name__ == '__main__':
    c = Solution()
    s = "PAYPALISHIRING"
    numRows = 3
    answer = "PAHNAPLSIIGYIR"
    print(c.convert(s, numRows))
    print(c.convert(s, numRows)==answer)